package org.fuxia.im.core.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.fuxia.im.core.entries.ECPacket;
import org.fuxia.im.core.entries.ECResponse;
import org.fuxia.im.core.utils.ObjectUtil;
import org.fuxia.im.db.dao.UserDaoImpl;

public class QueryUserService extends AbstractService
{

	@Resource
	private UserDaoImpl	userDao;

	@SuppressWarnings("rawtypes")
	public void service(ECPacket packet)
	{
		ECResponse resp = new ECResponse();
		String queryParam = packet.getParameter("condition");
		String userCode = packet.getParameter("self");
		String hql = "select imagePath,nickName,userCode,sex,age from IMUser where userCode!="
				+ userCode
				+ " and  userCode like :condition";
		try
		{
			List result = userDao.findByNamedParam(hql, new String[] { "condition" }, new Object[] { "%" + queryParam
			                                                                                         + "%" });
			resp.setStatusCode(200);
			resp.put("qresult", ObjectUtil.getJsonStr(result));
		}
		catch (Exception e)
		{
			e.printStackTrace();
			resp.setStatusCode(400);
			resp.setResponseText("查询数据失败");
		}
		resp.setResponseType("query_result");
		try
		{
			writeReponse(packet, resp);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

}
